<template>
  <div id="app" class="app-page">
    <root>
      <safe-header
        v-bind="{
          title: '出库复核',
          isBack: true,
          backIconColor: '#fff',
          fixedTop: true,
        }"
      />
      <div id="OutboundReview">
        <v-container class="py-6 px-2">
          <v-row>
            <v-col :cols="12" pb-0>
              <v-expansion-panels>
                <v-expansion-panel>
                  <v-expansion-panel-header>
                    待发货单
                    <p></p>
                    共[{{soMasterList.length}}]条
                  </v-expansion-panel-header>
                  <v-expansion-panel-content>
                    <v-simple-table>
                      <template v-slot:default>
                        <tbody>
                          <tr
                            v-for="item in soMasterList"
                            :key="item.name"
                            @click="boxCodeSearch(item)"
                          >
                            <td>{{ item.billNo }}</td>
                          </tr>
                        </tbody>
                      </template>
                    </v-simple-table>
                  </v-expansion-panel-content>
                </v-expansion-panel>
              </v-expansion-panels>
            </v-col>
          </v-row>
          <v-row class="mt-2">
            <v-col :cols="12" pb-0>
              <v-text-field
                :prepend-inner-icon="mdiCreditCardScan"
                v-model="outbillNo"
                solo
                autofocus
                clearable
                hide-details
                placeholder="出库单"
                @keydown.13="outBillSearch"
                style="font-size: 14px"
              ></v-text-field>
            </v-col>
          </v-row>
        </v-container>
        <v-container white class="pa-2 OutboundReview_bottom">
          <v-row>
            <v-col cols="12" class="d-flex align-center py-2">
              <span class="card-title">待发物料清单</span>
              <span class="card-title ml-2">{{ outMasterCode }}</span>
            </v-col>
          </v-row>
          <v-divider class="mb-2"></v-divider>
          <div v-if="pickTaskList[0]">
            <v-container v-for="(item, index) in pickTaskList" :key="index" class="px-1">
              <v-row>
                <v-col cols="12" class="pa-0 pb-2">
                  <v-card outlined style="background-color: #f2f3f5">
                    <v-card-subtitle class="list_content pa-1">
                      <v-row>
                        <v-col cols="2" class="pr-2 d-flex justify-center align-center">
                          <v-row>
                            <v-col class="pr-2 d-flex justify-center align-center">
                              <span>{{ index + 1 }}</span>
                            </v-col>
                          </v-row>
                          <v-divider vertical></v-divider>
                        </v-col>

                        <v-col cols="10">
                          <v-row class="d-flex flex-row justify-space-between wms-v-row">
                            <v-col cols="12" class="card-lable">
                              {{
                              item.itemCode
                              }}
                            </v-col>
                            
                          </v-row>
                          <v-row class="d-flex flex-row justify-space-between wms-v-row">
                            <v-col cols="12" class="card-lable">
                              {{
                              item.itemName
                              }}
                            </v-col>
                            
                          </v-row>
                          <v-row class="d-flex flex-row justify-space-between wms-v-row">
                            
                            <v-col cols="8" class="card-lable">
                              {{
                              item.batchName
                              }}
                              
                            </v-col>
                            <v-col class="card-value">
                              数量：{{
                              item.deliveryQuantity
                              }}
                            </v-col>
                          </v-row>
                        </v-col>
                      </v-row>
                    </v-card-subtitle>
                  </v-card>
                </v-col>
              </v-row>
            </v-container>
          </div>
          <v-row v-else>
            <v-col cols="12" class="text-center">暂无数据</v-col>
          </v-row>
        </v-container>
        <div v-show="hidshow" class="footer">
          <v-bottom-navigation height="60" style="background: transparent; box-shadow: none">
            <v-row class="pa-0 ma-0 justify-center" style="background: transparent">
              <v-col
                cols="12"
                class="pa-0 ma-0 d-flex justify-center align-center mb-2 px-2 py-1"
                style="background: transparent"
              >
                <v-btn
                  class="wms-submit-btn"
                  dark
                  block
                  color="#193690"
                  style="
                    height: 100%;
                    border-radius: 10px;
                    color: #fff !important;
                  "
                  @click="OutboundSubmit"
                >提交</v-btn>
              </v-col>
            </v-row>
          </v-bottom-navigation>
        </div>
      </div>
    </root>
    <v-overlay :value="overlay">
      <v-progress-circular indeterminate size="64"></v-progress-circular>
    </v-overlay>
  </div>
</template>

<script>
import SafeHeader from "../../components/safeHeader_wms";
import Root from "@/components/Root.vue";
import { mdiChevronRight, mdiCreditCardScan } from "@mdi/js";
import wms from "@/utils/business_wms";

export default {
  name: "OutboundReview",
  components: {
    SafeHeader,
    Root
  },
  data() {
    return {
      docmHeight: document.documentElement.clientHeight,
      showHeight: document.documentElement.clientHeight,
      hidshow: true,
      overlay: false,
      alert: false,
      outbillNo: "",
      outMasterCode: "",
      svgpath: mdiChevronRight,
      mdiCreditCardScan: mdiCreditCardScan,
      boxCode: "", // 出库容器号/单号
      pickTaskIds: "",
      cellCode: "",
      pickTaskList: [
        //拣货单列表
        // {
        //   itemCode: "IM21102-918-123",
        //   itemName: "物料名称",
        //   cellCode: "所属库位",
        //   batchName: "批次",
        //   pickQuantity: 110,
        //   boxCode: "CT-1001",
        // },
      ],
      soMasterList: [
        // {
        //   name: 'Frozen Yogurt',
        //   calories: 159,
        // },
        // {
        //   name: 'Ice cream sandwich',
        //   calories: 237,
        // },
        // {
        //   name: 'Eclair',
        //   calories: 262,
        // },
      ],
      // 当前出库单据类型--是否为调拨出库
      isDb: false,
      isCell: false,
      // 库区
      areaInfoList: [],
      erpAreaId: "",
      soMasterId: null
    };
  },

  mounted() {
    window.onresize = () => {
      return (() => {
        this.showHeight = document.body.clientHeight;
      })();
    };

    //获取待发货的so单
    let params = {
      wareId: localStorage.getItem("wareId"),
      states: 0 //拣货完成
    };
    wms
      .get({
        url: "/out/master/list",
        data: params
      })
      .then(res => {
        console.log(JSON.stringify(res));
        if (res.status == 200 && res.data.code == 200) {
          this.soMasterList = res.data.data.list;
        } else {
          alert(res.data.message);
          // this.overlay = false;
        }
      });
  },

  watch: {
    showHeight: function() {
      if (this.docmHeight > this.showHeight) {
        this.hidshow = false;
      } else {
        this.hidshow = true;
      }
    }
  },

  methods: {
    // 提交
    OutboundSubmit() {
      this.overlay = true;
      
      let billNos = [];
      billNos.push(this.outMasterCode);
      wms
        .post({
          url: "/out/master/sendOut",
          data: { billNos: billNos }
        })
        .then(res => {
          console.log(JSON.stringify(res));
          if (res.status == 200 && res.data.code == 200) {
            this.overlay = false;
            
            alert("提交成功!");
            window.location.reload();
          } else {
            alert(res.data.message);
            this.overlay = false;
          }
        });
    },

    // 下拉框选值
    getSelected(val) {
      this.erpAreaId = val;
      console.log(this.erpAreaId);
    },
    outBillSearch() {
      //根据出库单查询对应的明细
      this.overlay = true;
      this.soMasterList.forEach(item => {
        if (item.billNo == this.outbillNo) {
          this.soMasterId = item.soMasterId;
        }
      });
      if (!this.soMasterId) {
        this.outbillNo = "";
        alert("出库单不存在!!!");
        return false;
      }
      wms
        .get({
          url: "/out/master/detail/groupList",
          data: { billNo: this.outbillNo }
        })
        .then(res => {
          console.log(JSON.stringify(res));
          if (res.status == 200 && res.data.code == 200) {
            //
            this.pickTaskList = res.data.data.list;
            console.log(JSON.stringify(this.pickTaskList));
            this.outMasterCode = this.pickTaskList[0].billNo;
            console.log(this.outMasterCode, "this.outMasterCode");
            this.overlay = false;
            // 增加逻辑判断是不是调拨出库
            // for (let item of this.soMasterList) {
            //   if (item.soMasterId == this.outMasterCode) {
            //     // 同一个出库任务--判断是否是调拨出库
            //     if (item.billType == 83) {
            //       this.isCell = true;
            //       //获取数据 打开库区下拉框
            //       // wms
            //       //   .get({
            //       //     url: "/area/infos/list",
            //       //     data: null
            //       //   })
            //       //   .then(res => {
            //       //     // console.log(JSON.stringify(res.data.data.list));
            //       //     if (res.status == 200 && res.data.code == 200) {
            //       //       this.areaInfoList = res.data.data.list;
            //       //     } else {
            //       //       alert(res.data.message);
            //       //     }
            //       //   });
            //     }
            //     break;
            //   } else {
            //     continue;
            //   }
            // }
          } else {
            alert(res.data.message);
            this.overlay = false;
          }
        });
    },
    // 容器单号查询
    boxCodeSearch(item) {
      //根据出库单查询对应的明细
      this.overlay = true;
      this.soMasterId = item.soMasterId;
      wms
        .get({
          url: "/out/master/detail/groupList",
          data: { billNo: item.billNo }
        })
        .then(res => {
          console.log(JSON.stringify(res));
          if (res.status == 200 && res.data.code == 200) {
            //
            this.pickTaskList = res.data.data.list;
            console.log(JSON.stringify(this.pickTaskList));
            this.outMasterCode = this.pickTaskList[0].billNo;
            console.log(this.outMasterCode, "this.outMasterCode");
            this.overlay = false;
            // 增加逻辑判断是不是调拨出库
            // for (let item of this.soMasterList) {
            //   if (item.soMasterId == this.outMasterCode) {
            //     // 同一个出库任务--判断是否是调拨出库
            //     if (item.billType == 83) {
            //       this.isCell = true;
            //       //获取数据 打开库区下拉框
            //       // wms
            //       //   .get({
            //       //     url: "/area/infos/list",
            //       //     data: null
            //       //   })
            //       //   .then(res => {
            //       //     // console.log(JSON.stringify(res.data.data.list));
            //       //     if (res.status == 200 && res.data.code == 200) {
            //       //       this.areaInfoList = res.data.data.list;
            //       //     } else {
            //       //       alert(res.data.message);
            //       //     }
            //       //   });
            //     }
            //     break;
            //   } else {
            //     continue;
            //   }
            // }
          } else {
            alert(res.data.message);
            this.overlay = false;
          }
        });
    }
  }
};
</script>

<style lang="scss" scoped>
.footer {
  position: absolute;
  padding-top: 65px;
  width: 100%;
  bottom: 0;
}

#app {
  .row {
    margin: 0;
  }
  .col {
    padding: 0;
  }
}
#OutboundReview {
  height: 100%;
  display: flex;
  flex-direction: column;
  .OutboundReview_bottom {
    flex: 1;
    padding-bottom: 68px !important;
  }
}
</style>
